package cn.bby.tools.actions.str;

import cn.bby.tools.utils.AnActionEventUtils;
import cn.hutool.core.util.StrUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;

/**
 * @author ben
 * @since 2025/9/24 21:15
 */
public abstract class BaseStringProcessAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        // 获取选中的文本
        String selectedText = AnActionEventUtils.getSelectedText(e);
        if (StrUtil.isEmpty(selectedText)) {
            return;
        }
        String newText = process(e, selectedText);
        if (selectedText.equals(newText)) {
            return;
        }
        AnActionEventUtils.replaceSelection(e, newText);
    }

    abstract public String process(AnActionEvent e, String selectedText);
}
